package com.zzyl.nursing.mapper;

import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface MemberReservationMapper {
    /**
     * 根据用户id和预约时间段查询预约数量
     * @param userId
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("select * from reservation where status=2 and update_by=#{userId} and update_time between #{startTime} and #{endTime}")
    Integer selectReservationCountByDay(@Param("userId") Long userId,@Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);


    /**
     * 根据用户id和预约时间查询预约数量
     * @param userId
     * @param time
     * @return
     */
    @Select("select time,6-count(*) as count from reservation where time between #{startTime} and #{endTime} and status !=2 group by time")
     List<Map<String,Object>> selectReservationCountByTime(@Param("userId") Long userId, @Param("time") Long time,@Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);

    /**
     * 插入预约信息
     * @param dto
     * @return
     */
    int insertReservation(Reservation dto);
}
